package Math;

import java.util.ArrayList;
import java.util.List;

public class _728_SelfDividingNumbers {
    public List<Integer> selfDividingNumbers(int left, int right) {
        List<Integer> resultList = new ArrayList<Integer>();
        for(int i=left;i<=right;i++) {
            int sub = 1;
            while (sub <= i / 10) {
                sub*=10;
            }
            int div = i/sub;
            int res = i%sub;
            boolean conf = true;
            while (sub != 0) {
                if (div == 0) {
                    conf = false;
                    break;
                }
                if (i % div != 0) {
                    conf = false;
                    break;
                }
                sub/=10;
                if (sub != 0) {
                    div = res / sub;
                    res = res % sub;
                }
            }
            if (conf) {
                resultList.add(i);
            }
        }
        return resultList;
    }
}
